// userPackage/pages/login/login.js
import { ajaxFun } from "../../../utils/ajax";
const md5 = require('md5');
Page({
  data:{
    username:"13344556789",
    password:"123"
  },
  onShow(){
    wx.getLocation({
      type: 'wgs84',
					geocode:true,
					success: function (res) {
					  console.log(res);
						// uni.setStorageSync('loca',obj)
					}
    })
  },
  getlocation(){
    wx.getLocation({
      type: 'wgs84',
					geocode:true,
					success: function (res) {
					  console.log(res);
						// uni.setStorageSync('loca',obj)
					}
    })
  },
 async loginFun(){
    let result=await ajaxFun("/user/login","post",
      {
        "loginName": this.data.username,
        "passwordMd5": md5(this.data.password)
      }
    )
    if(result.resultCode===200){
      wx.setStorageSync('token',result.data);//存token
       wx.showToast({
         title: '登录成功',
       })
       wx.switchTab({//底部导航
         url: '/pages/my/my',
       })
    }
  },
  kkk(e) {
    wx.getUserProfile({
      desc:'获取您的头像,昵称,性别',
      success:info=>{
        wx.login({
          success: (res)=> {
            let code = res.code;
            wx.request({
              url: 'https://jk.136.dianchuiguan.com.cn/api/wxlogin/login',
              method:"POST",
              data:{
                  code,
									name:info.userInfo.nickName,
									headurl:info.userInfo.avatarUrl,
									sex:info.userInfo.gender,
									type:1
              },
              success:function(res){
                  console.log(res);
              }
            })
          },
        });
      }
    })
  }
})